<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="项目名称" prop="xmName">
        <el-input v-model="queryParams.xmName" placeholder="请输入项目名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="企业名称" prop="qyName">
        <el-input v-model="queryParams.qyName" placeholder="请输入企业名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['guarantee:agreement:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['guarantee:agreement:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['guarantee:agreement:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['guarantee:agreement:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="agreementList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" type="index" prop="id" >
        <template slot-scope="scope">
          <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
        </template>
      </el-table-column>
      <el-table-column label="id" align="center" prop="id" />

      <el-table-column label="业务员" align="center" prop="userName" />
      <el-table-column label="状态" align="center">
        <template slot-scope="scope">
          <span>{{ statusDict[scope.row.status] }}</span>
        </template>
      </el-table-column>
      <el-table-column label="出函类型" align="center" prop="xmChType" />
      <el-table-column label="项目名称" align="center" prop="xmName" />
      <el-table-column label="标段" align="center" prop="xmNameLotList" />
      <el-table-column label="保函类型" align="center" prop="xmBhType" />
      <el-table-column label="中标金额" align="center" prop="xmMoney" />
      <el-table-column label="企业名称" align="center" prop="qyName" />
      <el-table-column label="返润" align="center" prop="ywFanMoney" />
      <el-table-column label="扣税" align="center" prop="ywTaxMoney" />
      <el-table-column label="业绩" align="center" prop="ywYeji" />
      <el-table-column label="出函日期" align="center" prop="bhDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.bhDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="230" fixed="right">
        <template slot-scope="scope">
          <el-button v-if="scope.row.status == 0" size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['guarantee:agreement:edit']">修改</el-button>
          <el-button v-if="scope.row.status != 0" size="mini" type="text" icon="el-icon-tickets" @click="openDetail(scope.row)"
           >详情</el-button>
          <el-button v-if="scope.row.status == 0" size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['guarantee:agreement:remove']">删除</el-button>
          <el-button v-if="scope.row.status == 0" size="mini" type="text" icon="el-icon-edit"
            @click="handleTijiao(scope.row)" v-hasPermi="['guarantee:agreement:edit']">提交</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改履约保函对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1360px" append-to-body>
      <el-form ref="form" :inline="true" :model="form" label-width="180px">
        <!-- 基本信息 -->
        <el-divider content-position="left">基本信息</el-divider>
        <div>
          <el-form-item label="是否补录" prop="isBulu" :rules="{ required: false, message: '请选择', trigger: 'blur' }">
            <el-select class="my_select" v-model="form.isBulu" placeholder="请选择是否补录">
              <el-option label="否" value="否"></el-option>
              <el-option label="是" value="是"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="出函类型" prop="xmChType" :rules="{ required: false, message: '请选择', trigger: 'blur' }">
            <el-select class="my_select" v-model="form.xmChType" placeholder="请选择出函类型">
              <el-option label="商保电子" value="商保电子"></el-option>
              <el-option label="商保纸质" value="商保纸质"></el-option>
              <el-option label="银行纸质" value="银行纸质"></el-option>
              <el-option label="银行电子" value="银行电子"></el-option>
              <el-option label="保险电子" value="保险电子"></el-option>
              <el-option label="保险纸质" value="保险纸质"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="保函类型" prop="xmBhType" :rules="{ required: false, message: '请选择', trigger: 'blur' }">
            <el-select class="my_select" v-model="form.xmBhType" @change="typeChange" placeholder="请选择保函类型">
              <el-option label="履约" value="履约"></el-option>
              <el-option label="预付款" value="预付款"></el-option>
              <el-option label="民工" value="民工"></el-option>
              <el-option label="质保" value="质保"></el-option>
              <el-option label="支付" value="支付"></el-option>
              <el-option label="其他" value="其他"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="受益人名称" prop="xmSyName" :rules="{ required: false, message: '请输入', trigger: 'blur' }">
            <el-input v-model="form.xmSyName" placeholder="请输入受益人名称" />
          </el-form-item>
          <el-form-item label="受益人类型" prop="xmSyType" :rules="{ required: false, message: '请选择', trigger: 'blur' }">
            <el-select class="my_select" v-model="form.xmSyType" placeholder="请选择受益人类型">
              <el-option label="民营" value="民营"></el-option>
              <el-option label="上市公司" value="上市公司"></el-option>
              <el-option label="国有" value="国有"></el-option>
              <el-option label="代理公司" value="代理公司"></el-option>
              <el-option label="其他" value="其他"></el-option>
            </el-select>
          </el-form-item>
        </div>

        <div>
          <el-form-item label="项目名称" prop="xmName" :rules="{ required: false, message: '请输入', trigger: 'blur' }">
            <el-input v-model="form.xmName" placeholder="请输入项目名称" />
          </el-form-item>
          <el-form-item label="项目所在省市" prop="xmShengAndShi"
            :rules="{ required: false, message: '请选择', trigger: 'blur' }">
            <el-cascader :options="areaData" class="my_select" v-model="form.xmShengAndShi" @change="handleAreaChange"
              placeholder="请选择项目所在省市"></el-cascader>
          </el-form-item>
          <el-form-item label="项目所在地" prop="xmAddress" :rules="{ required: false, message: '请输入', trigger: 'blur' }">
            <el-input v-model="form.xmAddress" placeholder="请输入项目所在地" />
          </el-form-item>
        </div>
        <div>
          <el-form-item label="项目类型" prop="xmType" :rules="{ required: false, message: '请选择', trigger: 'blur' }">
            <el-select class="my_select" v-model="form.xmType" placeholder="请选择项目类型">
              <el-option label="施工" value="施工"></el-option>
              <el-option label="采购" value="采购"></el-option>
              <el-option label="服务" value="服务"></el-option>
            </el-select>
          </el-form-item>
        </div>

        <div class="bd_box">
          <el-form-item v-for="(item, index) in form.xmNameLotList" :key="index" label="标段"
            :prop="'xmNameLotList.' + index" :rules="{
              required: false, message: '请输入', trigger: 'blur'
            }">
            <el-input class="lotInput" v-model="form.xmNameLotList[index]" placeholder="请输入内容" />
            <el-button v-if="index + 1 == form.xmNameLotList.length" size="small" type="primary" icon="el-icon-plus"
              @click="addLot()"></el-button>
            <el-button v-else size="small" type="danger" icon="el-icon-minus" @click="deleteLot(index)"></el-button>
          </el-form-item>
        </div>

        <div>
          <el-form-item label="是否特殊项目" prop="xmSpecial" :rules="{ required: false, message: '请选择', trigger: 'blur' }">
            <el-select class="my_select" v-model="form.xmSpecial" placeholder="请选择是否特殊项目">
              <el-option label="否" value="否"></el-option>
              <el-option label="延期项目" value="延期项目"></el-option>
              <el-option label="续保" value="续保"></el-option>
              <el-option label="涉外" value="涉外"></el-option>
              <el-option label="补充协议" value="补充协议"></el-option>
              <el-option label="倒开" value="倒开"></el-option>
              <el-option label="转开" value="转开"></el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="中标时间或合同签署时间" prop="xmDate" :rules="{ required: false, message: '请选择', trigger: 'blur' }">
            <el-date-picker clearable class="my_picker" v-model="form.xmDate" type="date" value-format="yyyy-MM-dd"
              placeholder="请选择中标时间或合同签署时间">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="中标金额" prop="xmMoney" :rules="[{ required: true, message: '请输入', trigger: 'blur' },{ pattern: /^-?(0|([1-9][0-9]*))(\.[\d]+)?$/, message: '请输入正确格式', trigger: 'blur' }]">
            <el-input v-model="form.xmMoney" placeholder="请输入中标金额" />
          </el-form-item>
          <el-form-item v-if="xmBhblshow" label="保函比例" prop="xmBhProportion"
            :rules="{ required: false, message: '请输入', trigger: 'blur' }">
            <el-input v-model="form.xmBhProportion" placeholder="请输入保函比例" />
          </el-form-item>
          <el-form-item label="工期" prop="xmGongqi" :rules="{ required: false, message: '请输入', trigger: 'blur' }">
            <el-input v-model="form.xmGongqi" placeholder="请输入工期" />
          </el-form-item>
        </div>

        <div>
          <el-form-item label="招文" prop="xmArticleUrl" :rules="{ required: false, message: '请上传', trigger: 'blur' }">
            <image-upload v-model="form.xmArticleUrl" />
          </el-form-item>
          <el-form-item label="中标通知" prop="xmZbUrl" :rules="{ required: false, message: '请上传', trigger: 'blur' }">
            <image-upload v-model="form.xmZbUrl" />
          </el-form-item>
          <el-form-item label="合同文件" prop="xmContractUrl" :rules="{ required: false, message: '请上传', trigger: 'blur' }">
            <image-upload v-model="form.xmContractUrl" />
          </el-form-item>
          <el-form-item label="受益人名称依据" prop="xmSyUrl" :rules="{ required: false, message: '请上传', trigger: 'blur' }">
            <image-upload v-model="form.xmSyUrl" />
          </el-form-item>
          <el-form-item label="项目名称依据" prop="xmXmmcyjUrl" :rules="{ required: false, message: '请上传', trigger: 'blur' }">
            <image-upload v-model="form.xmXmmcyjUrl" />
          </el-form-item>
          <el-form-item label="保函依据" prop="xmBhyjUrl" :rules="{ required: false, message: '请上传', trigger: 'blur' }">
            <image-upload v-model="form.xmBhyjUrl" />
          </el-form-item>
          <el-form-item label="工期依据" prop="xmGqyjUrl" :rules="{ required: false, message: '请上传', trigger: 'blur' }">
            <image-upload v-model="form.xmGqyjUrl" />
          </el-form-item>
        </div>


        <!-- 企业信息 -->
        <el-divider content-position="left">企业信息</el-divider>
        <div>
          <el-form-item label="企业名称" prop="qyName" :rules="{ required: false, message: '请输入', trigger: 'blur' }">
            <el-input v-model="form.qyName" placeholder="请输入企业名称" />
          </el-form-item>
          <el-form-item label="企业所在省市" prop="qyShengAndShi"
            :rules="{ required: false, message: '请选择', trigger: 'blur' }">
            <el-cascader :options="areaData" class="my_select" v-model="form.qyShengAndShi" @change="handleQyAreaChange"
              placeholder="请选择企业所在省市"></el-cascader>
          </el-form-item>
          <el-form-item label="企业地址" prop="qyAddress" :rules="{ required: false, message: '请输入', trigger: 'blur' }">
            <el-input v-model="form.qyAddress" placeholder="请输入企业地址" />
          </el-form-item>
          <el-form-item label="注册资金" prop="qyZcMoney" :rules="{ required: false, message: '请输入', trigger: 'blur' }">
            <el-input v-model="form.qyZcMoney" placeholder="请输入注册资金" />
          </el-form-item>
          <el-form-item label="企业成立时间" prop="qyClDate" :rules="{ required: false, message: '请选择', trigger: 'blur' }">
            <el-date-picker class="my_picker" clearable v-model="form.qyClDate" type="date" value-format="yyyy-MM-dd"
              placeholder="请选择企业成立时间">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="企业类型" prop="qyType" :rules="{ required: false, message: '请选择', trigger: 'blur' }">
            <el-select class="my_select" v-model="form.qyType" placeholder="请选择企业类型">
              <el-option label="施工企业" value="施工企业"></el-option>
              <el-option label="生产企业" value="生产企业"></el-option>
              <el-option label="贸易服务" value="贸易服务"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="企业最高资质" prop="qyZizhi" :rules="{ required: false, message: '请选择', trigger: 'blur' }">
            <el-select class="my_select" v-model="form.qyZizhi" placeholder="请选择企业最高资质">
              <el-option label="总一" value="总一"></el-option>
              <el-option label="总二" value="总二"></el-option>
              <el-option label="总三" value="总三"></el-option>
              <el-option label="专一" value="专一"></el-option>
              <el-option label="专二" value="专二"></el-option>
              <el-option label="专三" value="专三"></el-option>
              <el-option label="劳务不分等级" value="劳务不分等级"></el-option>
              <el-option label="高精特新" value="高精特新"></el-option>
              <el-option label="自有场地" value="自有场地"></el-option>
              <el-option label="租赁场地" value="租赁场地"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="特殊情况" prop="qySpecial" :rules="{ required: false, message: '请选择', trigger: 'blur' }">
            <el-select class="my_select" v-model="form.qySpecial" placeholder="请选择特殊情况">
              <el-option label="无" value="无"></el-option>
              <el-option label="企业失信" value="企业失信"></el-option>
              <el-option label="法人失信" value="法人失信"></el-option>
              <el-option label="法人限高" value="法人限高"></el-option>
              <el-option label="实控人股东限高" value="实控人股东限高"></el-option>
              <el-option label="被执行较多" value="被执行较多"></el-option>
              <el-option label="行政处罚" value="行政处罚"></el-option>
              <el-option label="终本" value="终本"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="发票类型" prop="qyFpType" :rules="{ required: false, message: '请选择', trigger: 'blur' }">
            <el-select class="my_select" v-model="form.qyFpType" placeholder="请选择发票类型">
              <el-option label="专票" value="专票"></el-option>
              <el-option label="普票" value="普票"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="发票名称" prop="qyKpName" :rules="{ required: false, message: '请输入', trigger: 'blur' }">
            <el-input v-model="form.qyKpName" placeholder="请输入开票名称" />
          </el-form-item>
          <el-form-item label="发票税号" prop="qyKpNum" :rules="{ required: false, message: '请输入', trigger: 'blur' }">
            <el-input v-model="form.qyKpNum" placeholder="请输入税号" />
          </el-form-item>
          <el-form-item label="发票电话" prop="qyKpPhone" :rules="[{ required: true, message: '请输入', trigger: 'blur' },{ pattern: /^-?(0|([1-9][0-9]*))(\.[\d]+)?$/, message: '请输入正确格式', trigger: 'blur' }]">
            <el-input v-model="form.qyKpPhone" placeholder="请输入开票电话" />
          </el-form-item>
          <el-form-item label="发票地址" prop="qyKpAddress" :rules="{ required: false, message: '请输入', trigger: 'blur' }">
            <el-input v-model="form.qyKpAddress" placeholder="请输入开票地址" />
          </el-form-item>
          <el-form-item label="发票开户行" prop="qyKpBank" :rules="{ required: false, message: '请输入', trigger: 'blur' }">
            <el-input v-model="form.qyKpBank" placeholder="请输入开票开户行" />
          </el-form-item>
          <el-form-item label="发票开户账号" prop="qyKpBankNum" :rules="[{ required: true, message: '请输入', trigger: 'blur' },{ pattern: /^-?(0|([1-9][0-9]*))(\.[\d]+)?$/, message: '请输入正确格式', trigger: 'blur' }]">
            <el-input v-model="form.qyKpBankNum" placeholder="请输入开户账号" />
          </el-form-item>
          <el-form-item label="邮寄地址" prop="qyKpSendAdress"
            :rules="{ required: false, message: '请输入', trigger: 'blur' }">
            <el-input v-model="form.qyKpSendAdress" placeholder="请输入邮寄地址" />
          </el-form-item>
        </div>

        <!-- 保函信息 -->
        <el-divider content-position="left">保函信息</el-divider>
        <div>
          <el-form-item label="出函类型" prop="xmChType" :rules="{ required: false, message: '请选择', trigger: 'blur' }">
            <el-select class="my_select" v-model="form.xmChType" placeholder="请选择出函类型">
              <el-option label="商保电子" value="商保电子"></el-option>
              <el-option label="商保纸质" value="商保纸质"></el-option>
              <el-option label="银行纸质" value="银行纸质"></el-option>
              <el-option label="银行电子" value="银行电子"></el-option>
              <el-option label="保险电子" value="保险电子"></el-option>
              <el-option label="保险纸质" value="保险纸质"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="出函机构及对接人" prop="xmChDjuser"
            :rules="{ required: false, message: '请输入', trigger: 'blur' }">
            <el-select class="my_select" v-model="form.xmChDjuser" placeholder="请选择出函机构及对接人">
              <el-option
                v-for="bLetter in bLetters"
                :key="bLetter.id"
                :label="bLetter.institution+'('+bLetter.name+')'"
                :value="bLetter.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="保函金额" prop="bhMoney" :rules="[{ required: true, message: '请输入', trigger: 'blur' },{ pattern: /^-?(0|([1-9][0-9]*))(\.[\d]+)?$/, message: '请输入正确格式', trigger: 'blur' }]">
            <el-input v-model="form.bhMoney" placeholder="请输入保函金额" />
          </el-form-item>
          <el-form-item label="特殊要求" prop="bhRemark" :rules="{ required: false, message: '请输入', trigger: 'blur' }">
            <el-input v-model="form.bhRemark" placeholder="请输入特殊要求" />
          </el-form-item>
          <el-form-item label="保函格式" prop="bhGeshi" :rules="{ required: false, message: '请选择', trigger: 'blur' }">
            <el-select class="my_select" v-model="form.bhGeshi" placeholder="请选择保函格式">
              <el-option label="独立" value="独立"></el-option>
              <el-option label="独立付条件" value="独立付条件"></el-option>
              <el-option label="一般" value="一般"></el-option>
              <el-option label="连带" value="连带"></el-option>
              <el-option label="无要求" value="无要求"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="格式上传" prop="bhGeshiUrl" :rules="{ required: false, message: '请上传', trigger: 'blur' }">
            <file-upload v-model="form.bhGeshiUrl" />
          </el-form-item>
        </div>
        <!-- 费用信息 -->
        <el-divider content-position="left">费用信息</el-divider>
        <div>
          <el-form-item label="收费" prop="fkMoney" :rules="[{ required: true, message: '请输入', trigger: 'blur' },{ pattern: /^-?(0|([1-9][0-9]*))(\.[\d]+)?$/, message: '请输入正确格式', trigger: 'blur' }]">
            <el-input v-model="form.fkMoney"  placeholder="请输入收费" />
          </el-form-item>
          <el-form-item label="有无合作方费用" prop="isBulu" :rules="{ required: false, message: '请选择', trigger: 'blur' }">
            <el-select class="my_select" v-model="form.isBulu" @change="fkHzChange" placeholder="请选择有无合作方费用">
              <el-option label="无" value="无"></el-option>
              <el-option label="有" value="有"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item v-if="fkHzShow" label="合作方费用" prop="fkHzMoney"
          :rules="[{ required: true, message: '请输入', trigger: 'blur' },{ pattern: /^-?(0|([1-9][0-9]*))(\.[\d]+)?$/, message: '请输入正确格式', trigger: 'blur' }]">
            <el-input v-model="form.fkHzMoney" placeholder="请输入合作方费用" />
          </el-form-item>
          <el-form-item v-if="fkHzShow" label="合作方付款" prop="fkHzUrl"
          :rules="[{ required: true, message: '请输入', trigger: 'blur' },{ pattern: /^-?(0|([1-9][0-9]*))(\.[\d]+)?$/, message: '请输入正确格式', trigger: 'blur' }]">
            <el-input v-model="form.fkHzUrl" placeholder="请输入合作方付款" />
          </el-form-item>
          <el-form-item label="公司收益" prop="fkShouyi" :rules="[{ required: true, message: '请输入', trigger: 'blur' },{ pattern: /^-?(0|([1-9][0-9]*))(\.[\d]+)?$/, message: '请输入正确格式', trigger: 'blur' }]">
            <el-input v-model="form.fkShouyi" placeholder="请输入公司收益" />
          </el-form-item>
          <el-form-item label="返润扣税" prop="fkFanrun" :rules="{ required: false, message: '请输入', trigger: 'blur' }">
            <el-input v-model="form.fkFanrun" placeholder="请输入返润扣税" />
          </el-form-item>
          <el-form-item label="业绩" prop="ywYeji" :rules="[{ required: true, message: '请输入', trigger: 'blur' },{ pattern: /^-?(0|([1-9][0-9]*))(\.[\d]+)?$/, message: '请输入正确格式', trigger: 'blur' }]">
            <el-input v-model="form.ywYeji" placeholder="请输入业绩" />
          </el-form-item>
          <el-form-item label="付款方式" prop="fkType" :rules="{ required: false, message: '请选择', trigger: 'blur' }">
            <el-select class="my_select" v-model="form.fkType" placeholder="请选择付款方式">
              <el-option label="对公（桦）" value="对公（桦）"></el-option>
              <el-option label="财务微信" value="财务微信"></el-option>
              <el-option label="对公（竟融）" value="对公（竟融）"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="付款凭证" prop="fkUrl" :rules="{ required: false, message: '请上传', trigger: 'blur' }">
            <file-upload v-model="form.fkUrl" />
          </el-form-item>
        </div>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 详情弹窗 -->
    <agreement-detail :form="detailform" :detailOpen="detailOpen" @changeDialog="changeDialog" />
  </div>
</template>

<script>
import { listAgreement, tijiao, getAgreement, delAgreement, addAgreement, updateAgreement } from "@/api/guarantee/agreement";
import { pcTextArr } from "element-china-area-data";
import {getBLetterList} from "@/api/guarantee/letter";
import AgreementDetail from '@/views/guarantee/detail/agreement'

export default {
  name: "Agreement",
  components: {
    AgreementDetail
  },
  data() {
    return {
      statusDict: {
        '0': '草稿',
        '2': '主管待审核',
        '4': '业务总待审核',
        '6': '财务待确认',
        '8': '运营待送审',
        '10': '运营待提交',
        '12': '财务核算成本',
        '14': '完成',
        '-1': ' 驳回'
      },
      // 合作方费用显示
      fkHzShow: false,
      //出函机构及负责人
      bLetters: [],
      // 保函比例显示
      xmBhblshow: false,
      // 省市数据
      areaData: pcTextArr,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 履约保函表格数据
      agreementList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        xmChDjuser: null,
        xmName: null,
        qyName: null
      },
      // 表单参数
      form: {},
      // 详情弹窗
      detailOpen: false,
      detailform: {}
    };
  },
  created() {
    this.getList();
    this.getBLetters();
  },
  methods: {
    /** 有无合作方费用修改 */
    fkHzChange(val) {
      if (val === '有') {
        this.fkHzShow = true
      } else {
        this.fkHzShow = false
      }
    },
    getBLetters(){
      let data  ={};
      getBLetterList().then(response => {
        this.bLetters = response.data;
        console.log(this.bLetters)
      });
    },
    /** 保函类型修改 */
    typeChange(val) {
      if (val === '履约' || val === '预付款') {
        this.xmBhblshow = true
      } else {
        this.xmBhblshow = false
      }
    },
    /** 删除标段 */
    deleteLot(index) {
      this.form.xmNameLotList.splice(index, 1)
    },
    /** 添加标段 */
    addLot() {
      this.form.xmNameLotList.push('')
    },

    /** 提交按钮操作 */
    handleTijiao(row) {
      this.$modal.confirm('是否确认提交履约保函项目为为"' + row.xmName + '"的数据项？').then(function () {
        return tijiao(row.id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("提交成功");
      }).catch(() => { });
    },
    /** 企业省市修改 */
    handleQyAreaChange(value) {
      this.form.qySheng = value[0]
      this.form.qyShi = value[1]
    },
    /** 省市修改 */
    handleAreaChange(value) {
      this.form.xmSheng = value[0]
      this.form.xmShi = value[1]
    },
    /** 查询履约保函列表 */
    getList() {
      this.loading = true;
      listAgreement(this.queryParams).then(response => {
        this.agreementList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        isBulu: null,
        status: null,
        xmChType: null,
        xmChDjuser: null,
        xmBhType: null,
        xmSyName: null,
        xmSyType: null,
        xmName: null,
        xmNameLotList: [''],
        xmShengAndShi: null,
        xmSheng: null,
        xmShi: null,
        xmAddress: null,
        xmType: null,
        xmSpecial: null,
        xmSpecialName: null,
        xmDate: null,
        xmMoney: null,
        xmBhProportion: null,
        xmGongqi: null,
        xmArticleUrl: null,
        xmZbUrl: null,
        xmContractUrl: null,
        xmSyUrl: null,
        xmXmmcyjUrl: null,
        xmBhyjUrl: null,
        xmGqyjUrl: null,
        qyName: null,
        qyShengAndShi: null,
        qySheng: null,
        qyShi: null,
        qyAddress: null,
        qyZcMoney: null,
        qyClDate: null,
        qyType: null,
        qyZizhi: null,
        qySpecial: null,
        qyFpType: null,
        qyKpName: null,
        qyKpNum: null,
        qyKpPhone: null,
        qyKpAddress: null,
        qyKpBank: null,
        qyKpBankNum: null,
        qyKpSendAdress: null,
        bhMoney: null,
        bhGeshi: null,
        bhGeshiUrl: null,
        bhRemark: null,
        fkMoney: null,
        fkType: null,
        fkUrl: null,
        fkHzMoney: null,
        fkHzUrl: null,
        fkHzType: null,
        fkShouyi: null,
        fkFanrun: null,
        yyAcceptanceOpinion: null,
        yyPrice: null,
        yySupplyUrl: null,
        yySpecialRemark: null,
        yyContractData: null,
        yyContractHg: null,
        yySupplyRemark: null,
        yyFandanbaoqianshu: null,
        yyYoujidanhao: null,
        ywTotalMoney: null,
        bankMoney: null,
        bankAccount: null,
        bankSf: null,
        bankMoney2: null,
        bankAccount2: null,
        bankSf2: null,
        ywFanMoney: null,
        ywTaxMoney: null,
        ywYeji: null,
        sfKp: null,
        bhDate: null,
        mailNum: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加履约保函";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getAgreement(id).then(response => {
        this.form = response.data;
        if (this.form.isBulu === '有') {
          this.fkHzShow = true
        } else {
          this.fkHzShow = false
        }
        if (this.form.xmBhType === '履约' || this.form.isBulu === '预付款') {
          this.xmBhblshow = true
        } else {
          this.xmBhblshow = false
        }
        this.form.xmShengAndShi = [this.form.xmSheng, this.form.xmShi]
        this.form.qyShengAndShi = [this.form.qySheng, this.form.qyShi]
        this.open = true;
        this.title = "修改履约保函";
      });
    },
    /** 详情按钮操作 */
    openDetail(row) {
      const id = row.id || this.ids
      getAgreement(id).then(response => {
        this.detailform = response.data;
        if (this.detailform.isBulu === '有') {
          this.detailform.fkHzShow = true
        } else {
          this.detailform.fkHzShow = false
        }
        if (this.detailform.xmBhType === '履约' || this.detailform.isBulu === '预付款') {
          this.detailform.xmBhblshow = true
        } else {
          this.detailform.xmBhblshow = false
        }
        this.detailform.xmShengAndShi = [this.detailform.xmSheng, this.detailform.xmShi]
        this.detailform.qyShengAndShi = [this.detailform.qySheng, this.detailform.qyShi]
        this.detailOpen = true;
      });
    },
    changeDialog(val) {
      this.detailOpen = val;
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        console.log(valid, 'valid')
        if (valid) {
          console.log(this.form, 'this.form')
          if (this.form.id != null) {
            updateAgreement(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAgreement(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除履约保函编号为"' + ids + '"的数据项？').then(function () {
        return delAgreement(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('guarantee/agreement/export', {
        ...this.queryParams
      }, `agreement_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style lang="scss" scoped>
.my_select {
  width: 204px;
}

.my_picker {
  width: 204px;
}

.lotInput {
  width: 150px;
  margin-right: 10px;
}

.bd_box {
  display: flex;
  flex-wrap: wrap;
}
</style>
